package com.cpr.ams.web.controller;

import com.cpr.ams.bean.ServiceRecord;
import com.cpr.ams.bean.ServiceResults;
import com.cpr.ams.bean.extend.ServiceRecordExtend;
import com.cpr.ams.service.ICheckUpService;
import com.cpr.ams.util.Result;
import com.jacky.base.utils.PageVM;
import com.sun.istack.internal.NotNull;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(description = "维修，清理,服务操作相关接口")
@Validated
@RestController
@RequestMapping("/checkup")
public class CheckUpController {
@Autowired
private ICheckUpService checkUpService;
    @ApiOperation(value = "插入或更新维修和清理")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键",dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(name = "description", value = "情况描述",paramType = "query",required = true),
            @ApiImplicitParam(name = "type", value = "服务类型维修or清洁",paramType = "query",required = true),
            @ApiImplicitParam(name = "applicationTime", value = "申请时间",paramType = "query",required = true),
            @ApiImplicitParam(name = "appointmentTime", value = "预约时间",paramType = "query",required = true),
            @ApiImplicitParam(name = "roomId", value = "房间id",paramType = "query",required = true),
            @ApiImplicitParam(name = "tenantId", value = "租户id",paramType = "query",required = true)
    })
    @PostMapping("/saveOrUpdateCheckUp")
    public Result saveOrUpdateCheckUp(Integer id, @NotNull String description, @NotNull String type,@NotNull String applicationTime,@NotNull String appointmentTime,@NotNull Integer roomId,@NotNull Integer tenantId){
        ServiceRecord sr=new ServiceRecord();
        sr.setId(id);
        sr.setDescription(description);
        sr.setType(type);
        sr.setApplicationTime(applicationTime);
        sr.setAppointmentTime(appointmentTime);
        sr.setServiceStatus("已申请");
        sr.setTenantId(tenantId);
        sr.setRoomId(roomId);
       checkUpService.saveOrUpdateCheckUp(sr);
        return Result.success("插入或更新成功");
    }
    @ApiOperation(value = "分页查询维修和清洁信息")
    @GetMapping("/pageQuery")
    @ApiImplicitParams({ @ApiImplicitParam(name = "page", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "type", value = "清洁，维修", paramType = "query")
    })
    public Result pageQuery(@NotNull Integer page, @NotNull Integer pageSize, String type) {
        PageVM<ServiceRecordExtend> pageVM = checkUpService.query(page,pageSize,type);
        return Result.success(pageVM);
    }
    @ApiOperation(value = "插入或更新房间服务结果")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键",dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(name = "processDesc", value = "服务情况描述",paramType = "query"),
            @ApiImplicitParam(name = "resultsAssess", value = "服务结果评估",paramType = "query"),
            @ApiImplicitParam(name = "serviceId", value = "服务记录id",paramType = "query",required = true),
            @ApiImplicitParam(name = "personnelId", value = "服务人员id",paramType = "query",required = true)
    })
    @PostMapping("/saveOrUpdateResult")
    public Result saveOrUpdateResult(Integer id, @NotNull String processDesc, @NotNull String resultsAssess,@NotNull Integer serviceId,@NotNull Integer personnelId){
        ServiceResults sr=new ServiceResults();
        sr.setId(id);
        sr.setProcessDesc(processDesc);
        sr.setResultsAssess(resultsAssess);
        sr.setServiceId(serviceId);
        sr.setPersonnelId(personnelId);
        checkUpService.saveOrUpdateResult(sr);
        return Result.success("插入或更新成功");
    }
}
